package com.ecube.maintenance.pojos;

import android.text.TextUtils;

import com.ecube.maintenance.biz.apis.impl.UserAction;
import com.ecube.maintenance.managers.PrefManager;
import com.ecube.maintenance.utils.GsonUtil;
import com.google.gson.Gson;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Trible Chen on 2014/9/3.
 */
public class UserInfo extends BaseInfo{

    String realName;
    String mobile;
    String carNO;
    String carBrand;
    String carSerial;
    String carModel;
    String carFactory;
    String logo;
    String pendingOrderId;
    String sid;
    CarInfo car;
    String driveMile;
    List<String> favoriteSPs;
    List<String> favoriteProducts;
    List<ProductInfo> tracks;

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getCarNO() {
        if ( carNO != null )
        return carNO.toUpperCase();
        return null;
    }

    public String getDriveMile() {
        return driveMile;
    }

    public void setDriveMile(String driveMile) {
        this.driveMile = driveMile;
    }

    public void setCarNO(String carNO) {
        if(carNO!= null){
            this.carNO = carNO.toUpperCase();
        } else this.carNO = carNO;
    }

    public String getCarBrand() {
        return carBrand;
    }

    public void setCarBrand(String carBrand) {
        this.carBrand = carBrand;
    }

    public String getCarSerial() {
        return carSerial;
    }

    public void setCarSerial(String carSerial) {
        this.carSerial = carSerial;
    }

    public String getCarModel() {
        return carModel;
    }

    public void setCarModel(String carModel) {
        this.carModel = carModel;
    }

    public String getCarFactory() {
        return carFactory;
    }

    public void setCarFactory(String carFactory) {
        this.carFactory = carFactory;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getPendingOrderId() {
        return pendingOrderId;
    }

    public void setPendingOrderId(String pendingOrderId) {
        this.pendingOrderId = pendingOrderId;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public CarInfo getCar() {
        return car;
    }

    public void setCar(CarInfo car) {
        this.car = car;
    }

    public List<String> getFavoriteSPs() {
        return favoriteSPs;
    }

    public void setFavoriteSPs(List<String> favoriteSPs) {
        this.favoriteSPs = favoriteSPs;
    }

    public List<String> getFavoriteProducts() {
        return favoriteProducts;
    }

    public void setFavoriteProducts(List<String> favoriteProducts) {
        this.favoriteProducts = favoriteProducts;
    }

    public List<ProductInfo> getTracks() {
        return tracks;
    }

    public void setTracks(List<ProductInfo> tracks) {
        this.tracks = tracks;
    }

    private static UserInfo instance;

    public static UserInfo getInstance(){
        if ( instance == null ){
            instance = getUserInfoFromSpf();
            if ( instance == null ){
                instance = new UserInfo();
            }
        }
        return instance;
    }
    public static void saveToSpf(UserInfo info){
        String user = new Gson().toJson(info,UserInfo.class);
        PrefManager.getInstance().putString("User",user);
        instance = info;
    }
    private static UserInfo getUserInfoFromSpf(){
        String user = PrefManager.getInstance().getString("User");
        UserInfo info = GsonUtil.getInfosFromJson(user, UserInfo.class);
        return  info;
    }
    public static boolean isLogin(){
        return !TextUtils.isEmpty(getInstance().sid);
    }
}
